package slh.movie;

import java.sql.Date;

public class Movie {
    private int movieId;
    private String title;
    private String director;
    private Date releaseDate;
    private String actors;
    private String genre;
    private String country;
    private String language;
    private int duration;
    private String description;
    private String coverImage;
    private double score;        // 评分(1.0-10.0)
    private int ratingCount;     // 评分人数

    // Getters and setters
    public int getMovieId() { return movieId; }
    public void setMovieId(int movieId) { this.movieId = movieId; }

    public String getTitle() { return title; }
    public void setTitle(String title) { this.title = title; }

    public String getDirector() { return director; }
    public void setDirector(String director) { this.director = director; }

    public Date getReleaseDate() { return releaseDate; }
    public void setReleaseDate(Date releaseDate) { this.releaseDate = releaseDate; }

    public String getActors() { return actors; }
    public void setActors(String actors) { this.actors = actors; }

    public String getGenre() { return genre; }
    public void setGenre(String genre) { this.genre = genre; }

    public String getCountry() { return country; }
    public void setCountry(String country) { this.country = country; }

    public String getLanguage() { return language; }
    public void setLanguage(String language) { this.language = language; }

    public int getDuration() { return duration; }
    public void setDuration(int duration) { this.duration = duration; }

    public String getDescription() { return description; }
    public void setDescription(String description) { this.description = description; }

    public String getCoverImage() { return coverImage; }
    public void setCoverImage(String coverImage) { this.coverImage = coverImage; }

    // 新增的评分相关方法
    public double getScore() { return score; }
    public void setScore(double score) {
        // 确保评分在1.0-10.0范围内
        this.score = Math.max(1.0, Math.min(10.0, score));
    }

    public int getRatingCount() { return ratingCount; }
    public void setRatingCount(int ratingCount) {
        this.ratingCount = Math.max(0, ratingCount);
    }

    // 添加一个便捷方法来更新评分
    public void addRating(double newScore) {
        double totalScore = this.score * this.ratingCount + newScore;
        this.ratingCount++;
        this.score = totalScore / this.ratingCount;
    }

    // 可选：获取格式化评分(保留1位小数)
    public String getFormattedScore() {
        return String.format("%.1f", score);
    }
}